<template>
    <!-- 建筑垃圾处理方案 -->
    <div>
        <div class="basicCell">
            <div class="basicCellTitle">建筑垃圾处理方案</div>
            <el-form ref="formWeightInfo" :model="formData" :rules="rulesWeightInfo" label-width="150px">
                <div class="basicSubtitle">工程渣土</div>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="产生总量（t）:" prop="name">
                            <!-- <el-input readOnly v-model="residueWeightInfoTotal" /> -->
                            <el-input readOnly v-model="formData.residueWeightInfoTotal" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <div v-for="(item, index) in formData.residueWeightInfoList" :key="index">
                    <el-row>
                        <el-col :span="10">
                            <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="'residueWeightInfoList.' + index + '.weight'" :rules="rulesWeightInfo.weight">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="item.weight" :rules="rulesWeightInfo.weight"> -->
                                <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" prop="weight"> -->
                                <el-input v-model="item.weight" type="number" placeholder="请输入,保留小数点后两位；若无请输入0" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="10">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="item.constructionFactoryId" :rules="rulesWeightInfo.constructionFactoryId"> -->
                                <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="'residueWeightInfoList.' + index + '.constructionFactoryId'" :rules="rulesWeightInfo.constructionFactoryId">
                                <el-select class="fillUp" v-model="item.constructionFactoryId" clearable placeholder="请选择">
                                    <el-option
                                        v-for="(v,i) in placeList"
                                        :key="i"
                                        :label="v.label"
                                        :value="v.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        
                        <el-col :span="4" style="padding: 0 10px;">
                            <el-button icon="el-icon-plus" circle @click="addResidue(item, index, 'residueWeightInfoList')"></el-button>
                            <el-button icon="el-icon-minus" v-if="index>2" circle @click="delResidue(item, index, 'residueWeightInfoList')"></el-button>
                        </el-col>
                    </el-row>
                </div>
                <div class="basicSubtitle">工程泥浆</div>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="产生总量（t）:" prop="name">
                            <el-input readOnly v-model="residueWeightInfoTotal2" placeholder="请输入,保留小数点后两位；若无请输入0" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <div v-for="(item, index) in formData.residueWeightInfoList2" :key="index">
                    <el-row>
                        <el-col :span="10">
                            <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="'residueWeightInfoList2.' + index + '.weight'" :rules="rulesWeightInfo.weight">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="item.weight" :rules="rulesWeightInfo.weight"> -->
                                <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" prop="weight"> -->
                                <el-input v-model="item.weight" placeholder="请输入,保留小数点后两位；若无请输入0" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="10">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="item.constructionFactoryId" :rules="rulesWeightInfo.constructionFactoryId"> -->
                                <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="'residueWeightInfoList2.' + index + '.constructionFactoryId'" :rules="rulesWeightInfo.constructionFactoryId">
                                <el-select class="fillUp" v-model="item.constructionFactoryId" clearable placeholder="请选择">
                                    <el-option
                                        v-for="(v,i) in placeList"
                                        :key="i"
                                        :label="v.label"
                                        :value="v.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        
                        <el-col :span="4" style="padding: 0 10px;">
                            <el-button icon="el-icon-plus" circle @click="addResidue(item, index, 'residueWeightInfoList2')"></el-button>
                            <el-button icon="el-icon-minus" v-if="index>1" circle @click="delResidue(item, index, 'residueWeightInfoList2')"></el-button>
                        </el-col>
                    </el-row>
                </div>
                <div class="basicSubtitle">拆除垃圾</div>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="产生总量（t）:" prop="name">
                            <el-input readOnly v-model="residueWeightInfoTotal3" placeholder="请输入,保留小数点后两位；若无请输入0" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <div v-for="(item, index) in formData.residueWeightInfoList3" :key="index">
                    <el-row>
                        <el-col :span="10">
                            <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="'residueWeightInfoList3.' + index + '.weight'" :rules="rulesWeightInfo.weight">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="item.weight" :rules="rulesWeightInfo.weight"> -->
                                <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" prop="weight"> -->
                                <el-input v-model="item.weight" placeholder="请输入,保留小数点后两位；若无请输入0" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="10">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="item.constructionFactoryId" :rules="rulesWeightInfo.constructionFactoryId"> -->
                                <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="'residueWeightInfoList3.' + index + '.constructionFactoryId'" :rules="rulesWeightInfo.constructionFactoryId">
                                <el-select class="fillUp" v-model="item.constructionFactoryId" clearable placeholder="请选择">
                                    <el-option
                                        v-for="(v,i) in placeList"
                                        :key="i"
                                        :label="v.label"
                                        :value="v.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        
                        <el-col :span="4" style="padding: 0 10px;">
                            <el-button icon="el-icon-plus" circle @click="addResidue(item, index, 'residueWeightInfoList3')"></el-button>
                            <el-button icon="el-icon-minus" v-if="index>1" circle @click="delResidue(item, index, 'residueWeightInfoList3')"></el-button>
                        </el-col>
                    </el-row>
                </div>
                <div class="basicSubtitle">装修垃圾</div>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="产生总量（t）:" prop="name">
                            <el-input readOnly v-model="residueWeightInfoTotal4" placeholder="请输入,保留小数点后两位；若无请输入0" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <div v-for="(item, index) in formData.residueWeightInfoList4" :key="index">
                    <el-row>
                        <el-col :span="10">
                            <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="'residueWeightInfoList4.' + index + '.weight'" :rules="rulesWeightInfo.weight">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" :prop="item.weight" :rules="rulesWeightInfo.weight"> -->
                                <!-- <el-form-item :label="item.disposalTypeDesc + '量(t):'" prop="weight"> -->
                                <el-input v-model="item.weight" placeholder="请输入,保留小数点后两位；若无请输入0" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="10">
                            <!-- <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="item.constructionFactoryId" :rules="rulesWeightInfo.constructionFactoryId"> -->
                                <el-form-item :label="item.disposalTypeDesc + '地点：'" :prop="'residueWeightInfoList4.' + index + '.constructionFactoryId'" :rules="rulesWeightInfo.constructionFactoryId">
                                <el-select class="fillUp" v-model="item.constructionFactoryId" clearable placeholder="请选择">
                                    <el-option
                                        v-for="(v,i) in placeList"
                                        :key="i"
                                        :label="v.label"
                                        :value="v.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        
                        <el-col :span="4" style="padding: 0 10px;">
                            <el-button icon="el-icon-plus" circle @click="addResidue(item, index, 'residueWeightInfoList4')"></el-button>
                            <el-button icon="el-icon-minus" v-if="index>1" circle @click="delResidue(item, index, 'residueWeightInfoList4')"></el-button>
                        </el-col>
                    </el-row>
                </div>
                
                
                <div class="basicSubtitle">产生总量（t）: <span style="color: red;">{{totalAll}}</span></div>
                <!-- <el-button @click="aa"> 校验 </el-button> -->
            </el-form>
        </div>
        <div class="baAddRightBtm">
            <el-button type="primary" @click="next">暂存</el-button>
            <el-button type="primary" v-if="stepActive != 0" @click="back">上一步</el-button>
            <el-button type="primary" v-if="stepActive < 3" @click="next">下一步</el-button>
            <el-button type="primary" v-if="stepActive == 3" @click="next">确认</el-button>
        </div>
    </div>
  </template>
  
  <script>
  export default {
    name: "Record",
    components: {  },
    data() {
      return {
        stepActive: 0, // 进度
        formData: { // 表单数据
            residueWeightInfoTotal: null,
            residueWeightInfoList: [{ // 工程渣土
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "SPOT_UTILIZATION",
                disposalTypeDesc: "就地利用",
                weight: null,
            },{
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "OUTBOUND_DISPOSAL",
                disposalTypeDesc: "外运处置",
                weight: null,
            },{
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "EARTHWORK_BALANCE",
                disposalTypeDesc: "土方平衡",
                weight: null,
            }],
            residueWeightInfoList2: [{ // 工程渣土
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "SPOT_UTILIZATION",
                disposalTypeDesc: "就地利用",
                weight: null,
            },{
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "OUTBOUND_DISPOSAL",
                disposalTypeDesc: "外运处置",
                weight: null,
            }],
            residueWeightInfoList3: [{ // 工程渣土
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "SPOT_UTILIZATION",
                disposalTypeDesc: "就地利用",
                weight: null,
            },{
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "OUTBOUND_DISPOSAL",
                disposalTypeDesc: "外运处置",
                weight: null,
            }],
            residueWeightInfoList4: [{ // 工程渣土
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "SPOT_UTILIZATION",
                disposalTypeDesc: "就地利用",
                weight: null,
            },{
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "OUTBOUND_DISPOSAL",
                disposalTypeDesc: "外运处置",
                weight: null,
            }],
            tableDataTrans: []
        }, 
        rulesBasic: null, // 校验
        typeList: [],

        // 建筑垃圾处理方案 ===================================
        rulesWeightInfo: {
            weight: [
                { required: true, trigger: "blur", message: "请输入" },
                { pattern: /^\d+.?\d{0,2}$/, message: "保留小数点后两位", trigger: "blur" }
            ],
            constructionFactoryId: [
                { required: true, trigger: "change", message: "请选择" },
            ]
        },
        // 渣土类型
        disposalTypeList: [{ // 
            label: "就地利用", value: "SPOT_UTILIZATION",
            label: "外运处置", value: "OUTBOUND_DISPOSAL",
            label: "土方平衡", value: "EARTHWORK_BALANCE",
        }],
        placeList: [
            {value: '1', label: '处置地点1'},
            {value: '2', label: '处置地点2'},
            {value: '3', label: '处置地点3'},
            {value: '4', label: '处置地点4'},
            {value: '5', label: '处置地点5'},
            {value: '6', label: '处置地点6'}
        ],

      };
    },
    created() {
    },
    
    computed: {
        residueWeightInfoTotal() {
                let countNum = 0
                for(let i=0; i<this.formData.residueWeightInfoList.length; i++){
                    
                    countNum = countNum + Number(this.formData.residueWeightInfoList[i].weight)
                }
                return countNum
        },
        residueWeightInfoTotal2() {
                let countNum = 0
                for(let i=0; i<this.formData.residueWeightInfoList2.length; i++){
                    
                    countNum = countNum + Number(this.formData.residueWeightInfoList2[i].weight)
                }
                return countNum
        },
        residueWeightInfoTotal3() {
                let countNum = 0
                for(let i=0; i<this.formData.residueWeightInfoList3.length; i++){
                    
                    countNum = countNum + Number(this.formData.residueWeightInfoList3[i].weight)
                }
                return countNum
        },
        residueWeightInfoTotal4() {
                let countNum = 0
                for(let i=0; i<this.formData.residueWeightInfoList4.length; i++){
                    
                    countNum = countNum + Number(this.formData.residueWeightInfoList4[i].weight)
                }
                return countNum
        },
        totalAll() {
            return this.residueWeightInfoTotal + this.residueWeightInfoTotal2 + this.residueWeightInfoTotal3 + this.residueWeightInfoTotal4
        }
    },
    watch: {
        residueWeightInfoTotal(val){
            this.formData.residueWeightInfoTotal = val
        }
    },
    methods: {
        next(){
            this.$emit("next")
        },
        back(){
            this.$emit("back")
        },
        // 建筑垃圾处理方案 =======================
        addResidue(val, index, keyVul){
            let itemData = {
                constructionFactoryId: null,
                constructionFactoryName: "",
                disposalType: "",
                disposalTypeDesc: "",
                weight: null,
            }
            itemData.disposalType = val.disposalType
            itemData.disposalTypeDesc = val.disposalTypeDesc
            this.formData[keyVul].push(itemData)
        },
        delResidue(val, index, keyVul) {
            this.formData[keyVul].splice(index, 1);
        },
        aa(){
            this.$refs.formWeightInfo.validate(valid => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
    }
  };
  </script>
  
  <style scoped lang="scss" >
    .app-container{
       .baAdd{
        display: flex;
        .baAddLeft{
            width: 200px;
            max-height: 350px;
        }
        .baAddRight{
            width: calc(100% - 200px);
            font-size: 14px;
            font-weight: 500;
            line-height: 20px;
            letter-spacing: 0px;

            .baAddRightBasic{
                padding-bottom: 60px;
                .basicCellTitle{
                    font-size: 24px;
                    font-weight: bold;
                    line-height: 32px;
                    padding: 10px 0;
                }
                .basicSubtitle{
                    font-size: 18px;
                    font-weight: 600;
                    line-height: 28px;
                    letter-spacing: 0px;
                    padding: 10px 0;
                }
                .basicFence{
                    width: 100%;
                    min-height: 300px;
                    border: 1px solid;
                    border-radius: 5px;
                }
            }

            .el-select{
                width: 100%;
            }
            .baAddRightBtm{
                position: fixed;
                bottom: 0;
                width: 100%;
                width: calc(100% - 230px);
                text-align: center;
                height: 50px;
                background-color: white;
                padding-top: 10px;
                box-shadow: 0 -5px 10px rgba(0, 0, 0, 0.5);
            }
        }
       } 
    }
  </style>